package com.ali.common;

import org.apache.tomcat.util.codec.binary.Base64;

import java.nio.charset.StandardCharsets;

public class Base64Util {
    /**
     * Base64加密
     */
    public static String encrypt(String content) {
        byte[] contentByte = content.getBytes(StandardCharsets.UTF_8);
        return Base64.encodeBase64String(contentByte);
    }

    /**
     * Base64加密
     */
    public static String encrypt(byte[] contentByte) {
        return Base64.encodeBase64String(contentByte);
    }

    /**
     * Base64解密
     */
    public static String getStringByDecrypt(String encryptStr) {
        byte[] encryptStrByte = Base64.decodeBase64(encryptStr);
        return new String(encryptStrByte, StandardCharsets.UTF_8);
    }

    /**
     * Base64解密
     */
    public static byte[] getByteByDecrypt(String encryptStr) {
        return Base64.decodeBase64(encryptStr);
    }
}